
package com.noah.project.dao

import com.noah.project.model.Account
import org.apache.ibatis.annotations.*
import org.springframework.stereotype.Repository


@Repository
interface AccountDao {

    @Insert("INSERT INTO account (username, password, thirdId, regTime) VALUES(#{username}, #{password}, #{thirdId}, #{regTime})")
    @Options(useGeneratedKeys = true, keyProperty = "uid", keyColumn = "uid")//可以返回当前的uid,不加这行返回的是插入的行数
    fun insert(account: Account): Long

    @Delete("DELETE FROM account WHERE uid =#{uid}")
    fun delete(id: Long?): Long

    @Update("UPDATE account SET password = #{password}, thirdId = #{thirdId} WHERE uid = #{uid}")
    fun update(account: Account): Long

    @Select("SELECT * FROM account WHERE uid = #{uid}")
    fun findById(uid: Long?): Account?

    @Select("SELECT * FROM account WHERE username = #{username}")
    fun findByUsername(username: String?): Account?

    @Select("SELECT * FROM account")
    fun findAll(): List<Account>?
}
